package com.ccp.dev.qbdms.controller;

import com.ccp.dev.core.basic.annotion.Action;
import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.model.SysAuditModelType;
import com.ccp.dev.core.basic.response.ResultData;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.qbdms.model.Demo;
import com.ccp.dev.qbdms.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Action(ownermodel = SysAuditModelType.NULL)
//格式：项目名/模块名
@RequestMapping("/qbdms/qbdms")
public class DemoController  extends SysBaseController {

    @Autowired
    private DemoService demoService;

    /**
     * 添加示例
     * @param demo
     * @postmapping post表示添加 /qbdms为对象名称
     * @return
     */
    @PostMapping("/qbdms")
    public ResultData addDemo(@RequestBody Demo demo){
        demoService.addDemo(demo);
        return getResultDataSuccess("operation.success");
    }


    /**
     * 修改示例
     * @param demo
     * @putmapping put表示修改 /qbdms为对象名称
     * @return
     */
    @PostMapping("/qbdmsUpdate")
    public ResultData updateDemo(@RequestBody Demo demo){
        demoService.updateDemo(demo);
        return getResultDataSuccess("operation.success");
    }


    /**
     * 删除示例
     * @param demoId 示例ID
     * @postmapping post表示添加 /qbdmsId为删除的id
     * @return
     */
    @DeleteMapping("/{demoId}")
    public ResultData deleteDemo(@PathVariable String demoId){
        demoService.deleteDemo(demoId);
        return getResultDataSuccess("operation.success");
    }


    /**
     * 分页查询示例
     * @getmapping get表示查询 /qbdms为对象名称
     * @return
     */
    @GetMapping("/qbdms")
    public ResultData pageDemo(HttpServletRequest request){
        QueryFilter queryFilter = new QueryFilter(request);
        List<Demo> list = demoService.pageDemo(queryFilter);
        return getResultDataSuccess("operation.success",queryFilter.getPageBean().getTotalCount(),list);
    }

    /**
     * 单条查询示例
     * @getmapping get表示查询
     * @return
     */
    @GetMapping("/one")
    public ResultData getDemo(String id){
        Demo demo = demoService.getDemo(id);
        return getResultDataSuccess("get.success",demo);
    }
}
